//
//  PassengerView.m
//  JiongTu
//
//  Created by 杨璟 on 16/4/26.
//  Copyright © 2016年 YSKJ. All rights reserved.
//

#import "PassengerView.h"

#import "JTPassengerTrip.h"
#import "JTUser.h"

#import "UIView+Extension.h"
#import "UIImageView+WebCache.h"
#import <Masonry.h>

@interface PassengerView ()



@end

@implementation PassengerView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
    }
    return self;
}

- (void)setOneTrip:(JTPassengerTrip *)oneTrip {
    _oneTrip = oneTrip;
    
    UIImageView *icon = [[UIImageView alloc] init];
    UILabel *name = [[UILabel alloc] init];
    name.font = [UIFont systemFontOfSize:11];
    
    [self addSubview:icon];
    [self addSubview:name];
    
    [icon sd_setImageWithURL:oneTrip.passenger.iconPath placeholderImage:[UIImage imageNamed:@"头像占位"]];
    name.text = oneTrip.passenger.nickname;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    UIImageView *icon = [self.subviews firstObject];
    UILabel *name = [self.subviews lastObject];
    
    icon.width = 45;
    icon.height = 45;
    icon.x = 0;
    icon.y = 0;
    icon.layer.cornerRadius = icon.width * 0.5;
    icon.layer.masksToBounds = YES;
    
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(icon.mas_bottom).with.offset(6);
        make.centerX.equalTo(icon.mas_centerX);
    }];
}

@end
